/*
 * =====================================================================================
 *
 *       Filename:  sqlist.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  10/28/2010 07:33:40 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Orange (OS), 
 *        Company:  
 *
 * =====================================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include "sqlist.h"

sqlist *init_list() 
{
    sqlist *L;
	L = (elemtype *)malloc(LIST_INIT_SIZE*sizeof(elemtype));
	if(!L)
		return -1;
	L->length = 0;
	L->listsize = LIST_INIT_SIZE;
	return L; 
}
status destroy_list(sqlist *L)
{
	free(L->elem);
	L.elem = NULL;
	L.length = 0;
	L.listsize = 0;
	return OK;	
}

status clear_list(sqlist *L)
{
	L->length = 0;
	return OK;
}

status list_empty(sqlist *L)
{
	if(L->length == 0)
		return 1;
	else 
		return 0;
}
status list_length(sqlist *L)
{
	return L->length;
}
status get_elem(sqlist *L, int i, elemtype *e)
{
	if(i>1||i<L->length)
	{
		*e = *(L->elem+i-1);
		return OK;
	}else
		return -2;
}

status LocateElem(sqlist *L, elemtype e, compare())
{
	elemtype *p;
	int i = 0;

	while(i<L->length && compare(*p++, e))
	{
		i++;
	}

	if(i!= L-length)
		return i+1;
	else
		return -2;
}
status prior_elem(sqlist *L, elemtype cur_e, elemtype *pre_e)
{
	sqlist *p = L;

	while(*(p->elem) != cur_e&&*(p->elem))
	{
		p->elem++;
	}
	
	if(*(p->elem))
	{
		*pre_e = *(p->elem-1);
		return OK;
	}else{
		return -2;
	}
	
}
status next_elem(sqlist *L, elemtype cur_e, elemtype *next_e)
{
	int i = 1;
	elemtype *p = L->elem;
	while(i<L->length&&*P!=cur_e)
	{
		i++;
		p++;
	}
	if(i==L->length)
		return -2;
	else
	{
		*next_e = *--p;
		return OK;
	}	

}

status list_insert(sqlist *L, int i, elemtype *e) // insert postion i for e
{
    elemtype *q;

    if(i<1 || i>L->length+1) return -2;
    if(L->length >= L->listsize)
    {
        newbase = (elemtype *)realloc(L->elem, (L->listsize + LISTINCREMENT) * sizeof(elemtype));
        if(!newbase)
            return -1;
        L->elem = newbase;
        L->listsize += LISTINCRMENT;
    }

    q = &(L->elem[i-1];
    
            
}

    

status list_delete(sqlist *L, int i, elemtype e)
{
}

status list_traverse(sqlist *L, visit())
